package com.doublethread.easymart.modules.comment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doublethread.easymart.common.result.Result;
import com.doublethread.easymart.modules.comment.dto.CommentQueryDTO;
import com.doublethread.easymart.modules.comment.service.CommentService;
import com.doublethread.easymart.modules.comment.vo.CommentStatisticsVO;
import com.doublethread.easymart.modules.comment.vo.CommentVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 评价控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/comments")
@RequiredArgsConstructor
public class CommentController {

    private final CommentService commentService;

    /**
     * 获取商品评价列表
     */
    @GetMapping("/product/{productId}")
    public Result<Page<CommentVO>> getProductComments(@PathVariable Long productId,
                                                      CommentQueryDTO queryDTO) {
        log.info("获取商品评价列表");

        Page<CommentVO> commentPage = commentService.getProductComments(productId, queryDTO);

        log.info("获取商品评价列表成功");
        return Result.success(commentPage);
    }

    /**
     * 获取商品评价统计
     */
    @GetMapping("/product/{productId}/statistics")
    public Result<CommentStatisticsVO> getCommentStatistics(@PathVariable Long productId) {
        log.info("获取商品评价统计");

        CommentStatisticsVO statistics = commentService.getCommentStatistics(productId);

        log.info("获取商品评价统计成功");
        return Result.success(statistics);
    }
}
